#include <stdio.h>
#include "state.h"

typedef void (*statehandler)(stateMachine *sm);  //定义
statehandler state_array[] = {&handle_state_off,&handle_state_on};

/*对状态机进行初始化设置*/
void stateMachine_init(stateMachine *sm)
{
    sm -> nowstate = STATE_off;
    printf("初始化设置完成\n");
}

/*处理状态机为off状态的情况*/
void handle_state_off(stateMachine *sm)
{
    sm -> nowstate = STATE_on;
    printf("状态机状态切换为on\n");
}

/*处理状态机为on状态的情况*/
void handle_state_on(stateMachine *sm)
{
    sm -> nowstate = STATE_off;
    printf("状态机状态切换为off\n");
}

/*判断现在状态机的状态，再执行下一步操作*/
void button_event(stateMachine *sm)
{
    state_array[sm -> nowstate](sm);
}